package com.esreport.Utils;

import com.esreport.dto.ArticleInformation;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;

/**
 * 按发布时间排降序
 */
public class PublisDateCompare implements Comparator<ArticleInformation> {
    @Override
    public int compare(ArticleInformation o1, ArticleInformation o2) {
        Long pubStamp1 = null;
        Long pubStamp2 = null;
        try {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            pubStamp1 = sf.parse(o1.getPublishDate()).getTime();
            pubStamp2 = sf.parse(o2.getPublishDate()).getTime();

        }catch (ParseException e){
            e.printStackTrace();
        }
        return -( pubStamp1-pubStamp2>0?1: (pubStamp1==pubStamp2?0:-1));
    }
}
